package com.springboot.myspringbootframework.web.controller;

import com.springboot.myspringbootframework.domain.user.api.UserApi;
import com.springboot.myspringbootframework.domain.user.api.dto.UserDTO;
import com.springboot.myspringbootframework.web.aspect.LogAspect;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Controller
public class PageController {

    @Autowired
    private UserApi userApi;

    @GetMapping("/demo/hello")
    public String hello(Map<String, Object> map){
        map.put("hello", "from PageController");
        return "hello";
    }

    @LogAspect
    @GetMapping("/thymeleaf/getAll")
    public String getUsers(Map<String, Object> map){
        List<UserDTO> allUsers = userApi.getAllUsers();
        map.put("list",allUsers);
        return "hello";
    }

    @GetMapping("/index")
    public String index(){
        return "index";
    }
}
